package xml;

import cuShapes.ShapeList;
import java.util.Calendar;
import java.util.GregorianCalendar;

import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import javax.xml.bind.annotation.XmlElement;

/**
 * This is a container for the {@link cuShapes.ShapeList ShapeList} that wants to be save to an xml file.
 * @author mylesc,varunr
 *
 */
@XmlRootElement (name = "shapeCollection")
@XmlType(name = "ShapeCollectionType", propOrder={"shapes"})
@XmlAccessorType(XmlAccessType.FIELD)
public class ShapeCollection {

	@XmlAttribute(required=true)
	private long id;
	
	@XmlJavaTypeAdapter(value=ShapeCollectionAdapter.class)
	@XmlElement(name="shapeslist")
	private ShapeList shapes = new ShapeList();

	public ShapeList getShapeList() {
		if (shapes == null) {
            shapes = new ShapeList();
        }
        return this.shapes;
	}
	
	/**
	 * Used by JAXB to create an empty {@link xml.ShapeCollection ShapeCollection} object to be used while unmarshalling.
	 */
    // JAXB needs this default constructor
    public ShapeCollection() {}
    
    /**
     * Used by JAXB to create a marshallable representation of shapes.
     * @param shapes
     */
    public ShapeCollection(ShapeList shapes) {
        Calendar cal = new GregorianCalendar();
        this.setId(cal.getTimeInMillis());
        this.shapes = shapes;
    }

	public void setId(long id) {
		this.id = id;
	}

	public long getId() {
		return id;
	}
}
